/*******************************************************************************
 *  Copyright (c) 2010 Chase Technology Ltd.
 *  
 *  All rights reserved. This program and the accompanying materials
 *  are made available under the terms of the GNU General Public License v3.0
 *  which is available at http://www.gnu.org/licenses/
 * 
 * Contributors:
 *     Doug Satchwell - initial API and implementation
 *******************************************************************************/
package org.jfunction.ui.internal.editor;

import org.eclipse.jface.dialogs.StatusDialog;
import org.eclipse.jface.fieldassist.ComboContentAdapter;
import org.eclipse.jface.fieldassist.ContentProposalAdapter;
import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;

public class AddStepDialog extends StatusDialog {

	protected AddStepDialog(Shell parentShell) {
		super(parentShell);
		setTitle("Add Step");
	}
	
	@Override
	protected Control createDialogArea(Composite parent) {
		
		Composite textComp = new Composite(parent,SWT.NONE);
		GridData gd = new GridData(SWT.FILL,SWT.FILL,true,true);
		gd.heightHint = 50;
		gd.widthHint = 600;
		textComp.setLayoutData(gd);
		textComp.setLayout(new GridLayout());
		
		Label filterDescription = new Label(textComp,SWT.WRAP);
		gd = new GridData(SWT.FILL,SWT.FILL,true,false);
		filterDescription.setLayoutData(gd);
		filterDescription.setText("Enter step text:");
	
		Combo combo = new Combo(textComp, SWT.BORDER);
		gd = new GridData(SWT.FILL,SWT.FILL,true,false);
		combo.setLayoutData(gd);
//		
		ComboViewer cv = new ComboViewer(combo);
		cv.setContentProvider(new IStructuredContentProvider() {
			
			private String[] values;

			@Override
			public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
				this.values = (String[])newInput;
			}
			
			@Override
			public void dispose() {
			}
			
			@Override
			public Object[] getElements(Object inputElement) {
				return values;
			}
		});
		cv.setLabelProvider(new LabelProvider(){
			@Override
			public String getText(Object element) {
				return (String)element;
			}
		});
		String[] suggestedList = new String[]{"hello","world","hello world"};
		cv.setInput(suggestedList);

		ContentProposalAdapter cpAdapter = new ContentProposalAdapter(
			combo, new ComboContentAdapter(),
			new AutoComplete(suggestedList), null,
			FieldAssistUtil.getAlphaNumericChars()
		);
		cpAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
		
		return textComp;
	}	
}
